<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
        :modal-class="my-modal"
        dialog-class="modal-dialog"
        @hidden 关闭窗体触发事件
    -->
    <b-modal ref="my-modal" :title="title" scrollable @hidden="onHidden" hide-footer no-close-on-backdrop>
        <div class="d-block text-center">
            <div class="form-group m-form__group row">
                <label class="col-md-3 col-form-label">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                <div class="col-md-9">
                    <input class="form-control" disabled v-model="lcProForm.lc_process_title" placeholder="请输入">
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-lg-3 col-form-label">产&nbsp;品&nbsp;线</label>
                <div class="col-md-9">
                    <select class="form-control" disabled v-model="lcProForm.lcProductId" placeholder="请选择">
                        <option value="">请选择</option>
                        <option v-for="item in productList" 
                            :key="item.id" 
                            :label="item.name"
                            :value="item.id">
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-lg-3 col-form-label">产&nbsp;品&nbsp;组</label>
                <div class="col-md-9">
                    <input type="hidden" id="lcGroupIdTemp" />
                    <select class="form-control" disabled v-model="lcProForm.lcGroupId" placeholder="请选择">
                        <option value="">请选择</option>
                        <option v-for="item in groupList" 
                            :key="item.id" 
                            :label="item.name"
                            :value="item.id">
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-md-3 col-form-label">模块Key</label>
                <div class="col-md-9">
                    <input class="form-control"  disabled v-model="lcProForm.moduleKey" placeholder="请输入">
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            title: "流程信息",
            id: "",
            productList:[],
            groupList:[],
            lcProForm: {
                moduleKey: "",
                lcProductId: "",
                lcGroupId: "",
                lcGroupId_:"",
                title: "",
            },
        }
    },
    components: {
    },
    watch: {
        "lcProForm.lcProductId":{//监听字段变化
            handler:function(newVal,old){
                this.lcProForm.lcGroupId = "";
                this.lcProForm.lcGroupId_ = "";                
                if(newVal == "" || newVal == undefined || newVal == null){
                    this.groupList=[];
                }else{
                    this.initGroupList(newVal)
                }
                if(this.lcProForm.lcGroupId_ == "" || this.lcProForm.lcGroupId_ == undefined || this.lcProForm.lcGroupId_ == null){
                    
                }else{
                    this.lcProForm.lcGroupId = this.lcProForm.lcGroupId_;
                    this.lcProForm.lcGroupId_ = "";
                }
            }
        },
    },
    mounted() {

    },
    methods: {
        showModal(data) {
            this.$refs['my-modal'].show();
            if (null != data && undefined != data) {
                this.id = data.id;
                this.title = "流程信息";
                this.initProductList();
                this.getDetail(data);
            }

        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        onHidden() {//关闭窗体触发事件
            // this.$emit("change",null);
        },
        initProductList(){
            let params = {};
            apiUtil.post(process.env.VUE_APP_BPM_API + "/lcProduct/find", params).then(({ data }) => {
                this.productList = data.data;
            });
        },
        initGroupList(id){
            let params = {};
            apiUtil.query(process.env.VUE_APP_BPM_API + "/lcGroup/find/"+id, params).then(({ data }) => {
                this.groupList = data.data;
            });
        },
        getDetail(data) {
            apiUtil.get(process.env.VUE_APP_BPM_API + "/lcProcess/get/" + data.id).then(({ data }) => {
                this.lcProForm = data.data;
                this.initGroupList(this.lcProForm.lcProductId);
                this.lcProForm.lcGroupId_ = data.data.lcGroupId;
            });
        },
    }
}
</script>